package com.ftg.learn.springboot.comment.mapper;

import com.ftg.learn.springboot.comment.pojo.comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface commentMapper {

	@Insert("insert into comment(cid,comment,user,bid,star) values(#{cid},#{comment},#{user},#{bid},#{star})")
	int addComment(comment comment);

	@Update("UPDATE pageview SET PV=PV+1 WHERE id = 1")
	int pageView();

	@Select("SELECT * FROM brand b , COMMENT c WHERE b.`bid`=c.`bid` ORDER BY comtime DESC ")
	List<comment> showAA();


	//查所有个数
	@Select("select count(cid) from comment ")
	int countall();

	@Select("SELECT COMMENT,USER,star,bname,blogo FROM COMMENT c LEFT JOIN brand b  ON c.`bid`=b.`bid`  ORDER BY RAND() LIMIT 3")
	List<comment> randomComment();

	@Select("select count(bid) from brand where bname = #{bname}")
	int findBidcountByBname(String bname);

	@Select("select bid from brand where bname = #{bname}")
	String findBidByBname(String bname);


}
